home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 317 / asmsrc / bignum-c.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-20  |  2.4 KB  |  72 lines

  1. /* bignum_copy.c - */
  2.  
  3. /* Copyright (C) 1987 Free Software Foundation, Inc.
  4.  
  5. This file is part of Gas, the GNU Assembler.
  6.  
  7. The GNU assembler is distributed in the hope that it will be
  8. useful, but WITHOUT ANY WARRANTY.  No author or distributor
  9. accepts responsibility to anyone for the consequences of using it
  10. or for whether it serves any particular purpose or works at all,
  11. unless he says so in writing.  Refer to the GNU Assembler General
  12. Public License for full details.
  13.  
  14. Everyone is granted permission to copy, modify and redistribute
  15. the GNU Assembler, but only under the conditions described in the
  16. GNU Assembler General Public License.  A copy of this license is
  17. supposed to have been given to you along with the GNU Assembler
  18. so you can know your rights and responsibilities.  It should be
  19. in a file named COPYING.  Among other things, the copyright
  20. notice and this notice must be preserved on all copies.  */
  21.  
  22. #include "bignum.h"
  23.  
  24. /*
  25.  *            bignum_copy ()
  26.  *
  27.  * Copy a bignum from in to out.
  28.  * If the output is shorter than the input, copy lower-order littlenums.
  29.  * Return 0 or the number of significant littlenums dropped.
  30.  * Assumes littlenum arrays are densely packed: no unused chars between
  31.  * the littlenums. Uses bcopy() to move littlenums, and wants to
  32.  * know length (in chars) of the input bignum.
  33.  */
  34.  
  35. /* void */
  36. bignum_copy (in, in_length, out, out_length)
  37.      register LITTLENUM_TYPE *    in;
  38.      register int        in_length; /* in sizeof(littlenum)s */
  39.      register LITTLENUM_TYPE *    out;
  40.      register int        out_length; /* in sizeof(littlenum)s */
  41. {
  42.   register int    significant_littlenums_dropped;
  43.  
  44.   if (out_length < in_length)
  45.     {
  46.       register LITTLENUM_TYPE *    p; /* -> most significant (non-zero) input littlenum. */
  47.  
  48.       bcopy ((char *)in, (char *)out, out_length << LITTLENUM_SHIFT);
  49.       for (p = in + in_length - 1;   p >= in;   -- p)
  50.     {
  51.       if (* p) break;
  52.     }
  53.       significant_littlenums_dropped = p - in - in_length + 1;
  54.       if (significant_littlenums_dropped < 0)
  55.     {
  56.       significant_littlenums_dropped = 0;
  57.     }
  58.     }
  59.   else
  60.     {
  61.       bcopy ((char *)in, (char *)out, in_length << LITTLENUM_SHIFT);
  62.       if (out_length > in_length)
  63.     {
  64.       bzero ((char *)(out + out_length), (out_length - in_length) << LITTLENUM_SHIFT);
  65.     }
  66.       significant_littlenums_dropped = 0;
  67.     }
  68.   return (significant_littlenums_dropped);
  69. }
  70.  
  71. /* end: bignum_copy.c */
  72.